/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.netbrain.util;

import java.io.File;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import mx.netbrain.dao.TreeDao;
import mx.netbrain.dao.impl.TreeDaoImpl;
import mx.netbrain.model.Status;
import mx.netbrain.model.Tree;
import mx.netbrain.model.User;

/**
 *
 * @author gamma
 */
public class CreateFolderUtil {
    
    public static boolean createFolderUtil(String route) {
        File folder = new File(route);
        if (folder.mkdirs()) {
            return true;
        } else {
            return false;
        }
    }
    
    public static void createFolderDataBase(Tree tree, String name, User user) {
        Tree treeNew = new Tree();
        TreeDao treeDaoNew = new TreeDaoImpl();
        treeNew.setName(name);
        treeNew.setRoute(tree.getRoute() + treeNew.getId() + "\\");
        treeNew.setRoot(tree.getId());
        treeNew.setType("Carpeta");
        treeNew.setRegister(new Date());
        treeDaoNew.save(treeNew);
        treeNew.setRoute(tree.getRoute() + treeNew.getId() + "\\");
        treeDaoNew.update(treeNew);
    }
    
    public static void editFolderDataBase(Tree tree) {
        TreeDao treeDaoNew = new TreeDaoImpl();
        treeDaoNew.update(tree);
    }
    
    public static void deleteFolderDataBase(Tree tree) {
        Status status = new Status();
        status.setId(2);
        tree.setStatus(status);
        TreeDao treeDaoNew = new TreeDaoImpl();
        treeDaoNew.update(tree);
    }
    
}
